<?php


class tx_zlib_viewhelper_mailto extends tx_zlib_abstract_viewhelper
{

	/**
	 * Generates a mailto link.
	 *
     * If no arguments are passed, returns a tx_zlib_viewhelper_mailto object.
     *
	 * @param string $email
	 * @param string $name
	 * @param array $attribs
	 * @return string|tx_zlib_viewhelper_mailto
	 */
	public function mailto($email='', $name='', array $attribs = array())
	{
        if (0 == func_num_args()) {
            return $this;
        }
		return $this->link($email, $name, $attribs);
	}

	/**
	 * Generates a mailto link.
	 *
	 * @param string $email
	 * @param string $name
	 * @param array $attribs
	 * @return string
	 */
	public function link($email, $name='', array $attribs = array())
	{
		$parts = $this->getPi()->cObj->getMailTo($email, $name);
		if(!empty($parts)) {
			return sprintf('<a href="%s"%s>%s</a>', $parts[0], $this->htmlAttribs($attribs), $parts[1]);
		}
		return '';
	}

	/**
	 * Generates a mailto href.
	 *
	 * Use this for the href attribute of a link tag.
	 *
	 * @param string $email
	 * @return string
	 */
	public function href($email)
	{
		$parts = $this->getPi()->cObj->getMailTo($email, $email);
		if(!empty($parts)) {
			return $parts[0];
		}
		return '';
	}

}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_mailto.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/zlib/views/helpers/class.tx_zlib_viewhelper_mailto.php']);
}
